package cn.tedu.apps_system.controller;

import cn.tedu.apps_system.base.response.JsonResult;
import cn.tedu.apps_system.mapper.AUserMapper;
//import com.example.demo.base.response.JsonResult;
//import com.example.demo.base.response.ResultCode;
//import com.example.demo.mapper.UserMapper;
//import com.example.demo.pojo.dto.UserLoginParam;
//import com.example.demo.pojo.vo.UserVO;
import cn.tedu.apps_system.pojo.dto.AUserLoginDto;
import cn.tedu.apps_system.pojo.dto.UserLoginDto;
import cn.tedu.apps_system.pojo.dto.UserRegDto;
import cn.tedu.apps_system.pojo.vo.ProductVO;
import cn.tedu.apps_system.service.AUserService;
import cn.tedu.apps_system.service.GovernmentService;
import cn.tedu.apps_system.service.ProductService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;
import java.io.Serializable;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/v1/admin/user/")
@Api(tags = "02.管理模块")
public class AdminUserController {
    @Autowired
    private AUserService auserService;

    @Autowired
    private GovernmentService governmentService;
    @Autowired
    private ProductService productService;

    @PostMapping("login")
    @ApiOperation("登录功能")
    @ApiOperationSupport(order = 20)
    public JsonResult loginAUser(@RequestBody AUserLoginDto auserLoginDto, @ApiIgnore HttpSession session) {
        return auserService.loginAUser(auserLoginDto, session);
    }

    @GetMapping("logout")
    @ApiOperation("退出登录功能")
    @ApiOperationSupport(order = 40)
    public JsonResult Alogout(@ApiIgnore HttpSession session) {
        return auserService.logoutAUser(session);
    }


    // 用户管理
    @GetMapping("listUser")
    @ApiOperation("用户管理")
    @ApiOperationSupport(order = 60)
    public JsonResult listAUser(@ApiIgnore HttpSession session) {
        return auserService.listAUsers(session);
    }


    @GetMapping("delete/{id}")
    @ApiOperation("删除")
    @ApiOperationSupport(order = 60)
    public JsonResult deleteAUser(@Range(min = 1, max = 100, message = "编号必须在1-100之间")
                                  @PathVariable Long id, @ApiIgnore HttpSession session) {
        return auserService.deleteAUser(id, session);
    }

    /**
     * 公告展示
     **/

    @GetMapping("notice")
    @ApiOperation("公告管理")
    @ApiOperationSupport(order = 10)
    public JsonResult listNotice(@ApiIgnore HttpSession session) {
        return auserService.listAUsers(session);
    }
    @PutMapping("review/product/{id}")
    @ApiOperation("商品审核")
    @ApiOperationSupport(order = 70)
    public JsonResult reviewProduct(@PathVariable Long id) {
        productService.reviewProduct(id);
        return JsonResult.ok("审核成功");
    }

    @GetMapping("products/unreviewed")
    @ApiOperation("查询待审核商品列表")
    @ApiOperationSupport(order = 80)
    public JsonResult listUnreviewedProducts() {
        List<ProductVO> products = productService.listUnreviewedProducts();
        return JsonResult.ok(products);
    }

    @PutMapping("policy/review/{id}")
    @ApiOperation("审核政策")
    @ApiOperationSupport(order = 100)
    public JsonResult reviewPolicy(@PathVariable Long id) {
        return governmentService.reviewPolicy(id);
    }

    @DeleteMapping("policy/delete/{id}")
    @ApiOperation("删除政策")
    @ApiOperationSupport(order = 110)
    public JsonResult deletePolicy(@PathVariable Long id) {
        return governmentService.deletePolicy(id);
    }


}



